package com.doeis.uwork.dao;

import java.util.ArrayList;
import java.util.List;

import com.doeis.common.utils.StringUtils;
import com.doeis.uwork.entity.HnMsgAuthorityPeople;
import com.google.inject.Singleton;
import com.voland.core.db.Dao;
import com.voland.core.db.DaoException;
import com.voland.core.db.Page;

@Singleton
public class HnMsgAuthorityPeopleDao extends Dao {

	public HnMsgAuthorityPeople findHnMsgAuthorityPeopleByid(Object id) throws DaoException{
		try{
			return super.readById(HnMsgAuthorityPeople.class, id);
		}catch (Exception e) {
			throw new DaoException(e);
		}
	}

	public Page<HnMsgAuthorityPeople> listHnMsgAuthorityPeoples(Page page) throws DaoException{
		try{
			 String sql = "select * from hn_msg_authority_people";
			return super.querySlice(HnMsgAuthorityPeople.class, sql, page);
		}catch (Exception e) {
			throw new DaoException(e);
		}
	}

	public HnMsgAuthorityPeople findHnMsgAuthorityPeopleByForm(
			HnMsgAuthorityPeople form) {
		List<Object> params = new ArrayList<Object>();
		StringBuffer sql = new StringBuffer("select * from hn_msg_authority_people where true ");
		if (form!=null) {
			if (!StringUtils.isBlank(form.getSwitchboard_id())) {
				sql.append(" and switchboard_id=? ");
				params.add(form.getSwitchboard_id());
			}
			if (!StringUtils.isBlank(form.getUser_id())) {
				sql.append(" and user_id=? ");
				params.add(form.getUser_id());
			}
			if(!StringUtils.isBlank(form.getHn_msg_authority_id())){
				sql.append(" and hn_msg_authority_id !=?");
				params.add(form.getHn_msg_authority_id());
			}
		}
		return super.read(HnMsgAuthorityPeople.class, sql.toString(), params.toArray());
	}

	public List<HnMsgAuthorityPeople> findHnMsgAuthorityListByAuthorityId(
			String hn_msg_authority_id) {
		List<Object> params = new ArrayList<Object>();
		StringBuffer sql = new StringBuffer("select * from hn_msg_authority_people where true ");
		if (!StringUtils.isBlank(hn_msg_authority_id)) {
			sql.append(" and hn_msg_authority_id=? ");
			params.add(hn_msg_authority_id);
		}
		return super.query(HnMsgAuthorityPeople.class, sql.toString(), params.toArray());
	}
	
}